package com.example.mybatisplusgen.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.mybatisplusgen.service.BlogTagService;
import com.example.mybatisplusgen.pojo.BlogTag;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplusgen.utils.response.CommonResponse;

/**
 * <p>
 * 文章标签管理 前端控制器
 * </p>
 *
 * @author 又菜又爱玩
 * @since 2023-04-27
 */
@RestController
@RequestMapping("/blogTag")
public class BlogTagController {
        @Autowired
        private BlogTagService blogTagService;

        @PostMapping("/getList")
        public CommonResponse getList(@RequestBody BlogTag blogTag) {
            return CommonResponse.ok(blogTagService.selectBlogTagList(blogTag));
        }

        @DeleteMapping("/{id}")
        public CommonResponse deleteByID(Long id) {
            boolean b = blogTagService.deleteBlogTag(id);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("删除成功");
        }

        @PostMapping("/")
        public CommonResponse insert(@RequestBody BlogTag blogTag) {
            boolean b = blogTagService.insertBlogTag(blogTag);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("插入成功");
        }

        @PutMapping("/")
        public CommonResponse update(@RequestBody BlogTag blogTag) {
            boolean b = blogTagService.updateBlogTag(blogTag);
            if (!b) {
            return CommonResponse.fail();
            }
            return CommonResponse.ok("更新成功");
        }
}
